
package Server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import client.Login;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.*;
import ocsf.server.AbstractServer;
import ocsf.server.ConnectionToClient;

public class  BlockingUser {
	
	/*
	 * this class blocking user from ordering on the string[1] block comes from the gui the user name we want to block
	 * the we change the binary filed from 1 to 0 
	 * 
	 * @author Ariel
	 * @param con1 Connection to the database
	 * @param block Array of String which old the user name we want to block 
	 * @return  Array of String ,the name of the string is result and on result[1]=1 if we found user name and 0 if we didnt 
	 *
	 * 
	 * 
	 * 
	 */

	
	public static String[] blockhim(Connection con1,String[] block )
	{
		String[] result = new String[2];
		
		 try
         {
             Statement stmt = con1.createStatement();
           
            
             stmt.executeUpdate("UPDATE clients SET substate=0 WHERE  User_name='"+block[1]+"'");
           
             ResultSet res = stmt.executeQuery("SELECT * FROM clients WHERE User_name='"
						+ block[1] + "'");
             
             
             if (res.next()) {
            	
  				  				
     			result[1]="1";

     		} else     		
     			result[1]="2";

     		res.close();
     		
     	} catch (SQLException e) {
     		e.printStackTrace();
     	}
		
		
		return result;
		
	}

}
